﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Tetris
{
    class TcpSender
    {
        public TcpClient client { get; set; }
        public NetworkStream stream { get; set; }
        public BinaryFormatter formatter { get; set; }

        public TcpSender(String serv, int port)
        {
            this.client = new TcpClient(serv, port);
            this.stream = client.GetStream();
            this.formatter = new BinaryFormatter();
        }
        public void sendGame(Game g)
        {
            this.formatter.Serialize(stream, g);
        }
        public static String getIp()
        {
            IPHostEntry host;
            string localIP = "";
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    //Console.WriteLine(ip.ToString());
                    localIP = ip.ToString();
                }
            }
            return localIP;
        }
    }
}
